<%@page contentType="text/html; charset=UTF-8" import="com.pub.database.*,java.util.*" %>
<% response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); %>
<% response.setHeader("Cache.Control","no-cache"); response.setHeader("Pragma","no-cache"); response.setDateHeader("Expires",0);%>
<jsp:useBean id="WebFunction" scope="request" class="com.pub.web.WebFunction" />
<jsp:useBean id="DataViewForm" scope="request" class="com.pub.database.DataViewForm"/>

<jsp:setProperty name="DataViewForm" property="submitMethod" value="POST"/>
<jsp:setProperty name="DataViewForm" property="pageRowCount" value="10"/>
<jsp:setProperty name="DataViewForm" property="nowPageNum"/>
<jsp:setProperty name="DataViewForm" property="dataViewAction"/>
<jsp:setProperty name="DataViewForm" property="filterCol"/>
<jsp:setProperty name="DataViewForm" property="filterValue"/>
<jsp:setProperty name="DataViewForm" property="dvOrderByFields"/>
<jsp:setProperty name="DataViewForm" property="dvOrderBySeq"/>

<% WebFunction.setPortal_to_session(request); //set session from portal
//System.out.println(session.getAttribute("u_id"));
if (session.getAttribute("u_id")==null) {
  try {
    request.getRequestDispatcher((new StringBuffer("login.jsp")).insert(0, "/").toString()).forward(request, response);
  } catch (Exception le) {
    le.printStackTrace();
  }
  return;
}

  response.setContentType("text/html;charset=BIG5");
  request.setCharacterEncoding("BIG5");
  String flow_code = session.getAttribute("flow_code").toString();
  String strDBAlias = (request.getParameter("db_alias")==null ?"" :request.getParameter("db_alias"));
  if(strDBAlias.equals("")){
    return;
  }
  QueryBean gqbnDAO = new QueryBean(strDBAlias,true,"utf-8","utf-8");

  DataView dataView=null;
  dataView = new DataView(gqbnDAO);


  String strFlowCode = request.getParameter("flow_code")==null ? "":request.getParameter("flow_code");
  String strLoginUser = session.getAttribute("u_id")==null ? "" :session.getAttribute("u_id").toString();


  StringBuffer stbCondition = new StringBuffer();
  StringBuffer stbPageActionURI = new StringBuffer();

  stbPageActionURI.append(request.getRequestURI());
  stbPageActionURI.append("?db_alias=");
  stbPageActionURI.append(strDBAlias==null ? "" : strDBAlias);
  stbPageActionURI.append("&flow_code=");
  stbPageActionURI.append(strFlowCode==null ? "" : strFlowCode);


	//以下為動態產生欄位的程式
	
  ArrayList<Hashtable<String,Object>> laltColRelation = new ArrayList<Hashtable<String,Object>>();
  Hashtable<String,Object> lhtColRelationDetail = new Hashtable<String,Object>();
  ArrayList<String> laltLinkParamList=new ArrayList<String>();
  
  int lintLinkParamCount=0;
	
	//若flow_code為空值或多個，則以預設欄位輸出
	if(strFlowCode.equals("") || strFlowCode.indexOf(",")>-1){
		strFlowCode="NORMAL";
	}
	
	//讀取設定檔
  ResourceBundle rbdConf = ResourceBundle.getBundle(
                "WKF_JST_ENG", Locale.getDefault());
                
  //讀取該flow code要顯示的欄位個數
  int lintColCount = Integer.parseInt(rbdConf.getString(strFlowCode + ".COL_COUNT"));
  
  for(int i=1;i<=lintColCount;i++){
  	/**
  	* 因為每種欄位型態所需設定的屬性不一(有多有少)，但用ResourceBundle去讀properties時若沒有對的key會直接throws exception
  	* 所以以下的每一行都要各自用try-catch包住，然後在catch中把該屬性設為null
  	*/
  	try{lhtColRelationDetail.put(dataView.STR_FIELD_NAME, rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.STR_FIELD_NAME"));}catch(Exception se){lhtColRelationDetail.put(dataView.STR_FIELD_NAME,null);}
  	try{lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL,rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.STR_FIELD_SUB_SQL"));}catch(Exception se){lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL,null);}
	try{lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.STR_FIELD_TITLE"));}catch(Exception se){lhtColRelationDetail.put(dataView.STR_FIELD_TITLE,null);}
	try{lhtColRelationDetail.put(dataView.STR_FIELD_KIND, rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.STR_FIELD_KIND"));}catch(Exception se){lhtColRelationDetail.put(dataView.STR_FIELD_KIND,null);}
	try{lhtColRelationDetail.put(dataView.STR_FIELD_HTML, rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.STR_FIELD_HTML"));}catch(Exception se){lhtColRelationDetail.put(dataView.STR_FIELD_HTML,null);}
	try{lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.STR_FIELD_VALUE"));}catch(Exception se){lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,null);}
	try{lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.STR_FIELD_PROPERTY"));}catch(Exception se){lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,null);}
	  
	  //若是該欄位為LINK型態
	  if(rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.STR_FIELD_KIND").equals("LINK")){
	  	lhtColRelationDetail.put(dataView.STR_LINK_URI,rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.STR_LINK_URI"));
	  	
	  	lintLinkParamCount = Integer.parseInt(rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.LINK_PARAM.NUM"));
	  	for(int j=1;j<=lintLinkParamCount;j++){
	  		laltLinkParamList.add(rbdConf.getString(strFlowCode + "." + String.valueOf(i).trim() + ".dataView.LINK_PARAM." + String.valueOf(j).trim()));
	  	}
	  	
	  	lhtColRelationDetail.put(dataView.STR_LINK_PARAM,new ArrayList<String>(laltLinkParamList));
	  	
	  	laltLinkParamList.clear();
	  }
	  
	  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  	lhtColRelationDetail.clear();
  }


  DataViewForm.setColRelationUseArrayList(laltColRelation);
  DataViewForm.setJumpPageButtonShow(false);
  DataViewForm.setPageBtnOnTop(false);
  DataViewForm.setPageBtnOnButtom(true);
  DataViewForm.setFilterShow(false);
  DataViewForm.setJumpPageShow(true);
  DataViewForm.setRowsInfoShow(true);
  DataViewForm.setRowPageShow(false);
  DataViewForm.setExcelShow(false);
  DataViewForm.setOrderEnable(false);
  DataViewForm.setShowHeaderWhenNoData(true);
  DataViewForm.setAddNewShow(false);

  DataViewForm.setTableHeaderHtml("class='td_head_grid' align='center' width='680px'");
  DataViewForm.setPageActionURI(stbPageActionURI.toString());
  String strResult="";
  try{
    strResult=dataView.getOutputDataView(DataViewForm);
  }
  catch(Exception e){
    e.printStackTrace();
  }
  finally{

    try{gqbnDAO.close();gqbnDAO=null;}catch(Exception e){e.printStackTrace();}
 }

%>
<html>
<head>
<title>待處理事項</title>
<LINK HREF="/PUBPAGE/general/workflow.css" REL="STYLESHEET" TYPE="TEXT/CSS"/>
<base target='_self'/>
</head>
<body>
  <h4>待處理事項</h4>
  <form action="<%=request.getRequestURI()%>" method="POST">
    <table>
      <tr>
        <th>流程單別</th>
        <td><input type="text" name="flow_code" size="10" class="input" value="<%=(request.getParameter("flow_code")!=null ? request.getParameter("flow_code") : "")%>" /></td>
        <th>流程單號</th>
        <td><input type="text" name="flownum" size="13" maxlength="13" class="input" /></td>
        <th>送件人</th>
        <td><input type="text" name="sempno" size="8" maxlength="8" class="input" /></td>
        <td><input type="submit"  value="查詢" /></td>
      </tr>
    </table>
	<input type="hidden" name="db_alias" value="<%=request.getParameter("db_alias")%>"/>
<%=flow_code%>
  </form>
<%=strResult==null ? "":strResult%>
</body>
</html>
